package io.zhifei.modules.sys.system.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.*;
import io.zhifei.common.utils.PageUtils;
import io.zhifei.common.utils.R;
import io.zhifei.modules.sys.system.form.MailClassParam;
import io.zhifei.modules.sys.system.form.MailClassResult;
import io.zhifei.modules.sys.system.service.MailClassService;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;


/**
 * 班级邮件模板控制器
 *
 * @author duke
 * @Date 2021-06-07 14:40:27
 */
@RestController
@RequestMapping("/sys/mailClass")
@Api(value = "班级邮件模板Controller",tags = "班级邮件模板管理")
public class MailClassController extends AbstractController {


    @Resource
    private MailClassService mailClassService;

    /**
     * 新增接口
     *
     * @author duke
     * @Date 2021-06-07
     */
    @PutMapping("/addItem")
    @ApiOperation(value = "新增班级邮件模板",httpMethod = "PUT")
    public R addItem(MailClassParam mailClassParam) {
        mailClassParam.setCreateTime(new Date());
        this.mailClassService.add(mailClassParam);
        return R.ok();
    }

    /**
     * 编辑接口
     *
     * @author duke
     * @Date 2021-06-07
     */
    @PostMapping("/editItem")
    @ApiOperation(value = "修改班级邮件模板",httpMethod = "POST")
    public R editItem(MailClassParam mailClassParam) {
        this.mailClassService.update(mailClassParam);
        return R.ok();
    }

    /**
     * 删除接口
     *
     * @author duke
     * @Date 2021-06-07
     */
    @DeleteMapping("/delete")
    @ApiOperation(value = "删除班级邮件模板",httpMethod = "DELETE")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "主键",name = "id")
    })
    public R delete(@ApiIgnore MailClassParam mailClassParam) {
        mailClassParam.setFlag(1);
        this.mailClassService.update(mailClassParam);
        return R.ok();
    }

    /**
     * 查看详情接口
     *
     * @author duke
     * @Date 2021-06-07
     */
    @GetMapping("/getDetail")
    @ApiOperation(value = "查询班级邮件模板详情",httpMethod = "DELETE")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "主键",name = "id")
    })
    @ApiResponses({
            @ApiResponse(code = 200,message = "请求成功",response = MailClassResult.class)
    })
    public R detail(@ApiIgnore MailClassParam mailClassParam) {
        MailClassResult detail = this.mailClassService.findBySpec(mailClassParam);
        return R.ok().put("data",detail);
    }

    /**
     * 查询分页列表
     *
     * @author duke
     * @Date 2021-06-07
     */
    @GetMapping("/getPageList")
    @ApiOperation(value = "获取邮箱模板分页列表",httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页", required = true),
            @ApiImplicitParam(name = "pageSize", value = "当前页大小", required = true),
            @ApiImplicitParam(name = "title",value = "标题")
    })
    @ApiResponses({
            @ApiResponse(code = 200,message = "请求成功",response = MailClassResult.class)
    })
    public R getPageList(@ApiIgnore Integer page, @ApiIgnore Integer pageSize, @ApiIgnore MailClassParam mailClassParam) {
        PageUtils pageUtils = this.mailClassService.findPageBySpec(new Page(page,pageSize),mailClassParam);
        return R.ok().put("data",pageUtils);
    }

    /**
     * 查询列表
     *
     * @author duke
     * @Date 2021-06-07
     */
    @GetMapping("/getList")
    @ApiOperation(value = "获取邮箱模板列表",httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "title",value = "标题"),
            @ApiImplicitParam(name = "classId",value = "班级ID")
    })
    @ApiResponses({
            @ApiResponse(code = 200,message = "请求成功",response = MailClassResult.class)
    })
    public R getList(@ApiIgnore MailClassParam mailClassParam) {
        List<MailClassResult> mailClassResults = this.mailClassService.getList(mailClassParam);
        return R.ok().put("data",mailClassResults);
    }

    /**
     * 发送邮件
     * @param param
     * @return
     */
    @PostMapping(value = "/sendEmail")
    @ApiOperation(value = "发送邮件",httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "title",value = "标题"),
            @ApiImplicitParam(name = "content",value = "内容"),
            @ApiImplicitParam(name = "address",value = "地址")
    })
    public R sendEmail(@ApiIgnore MailClassParam param){
        return this.mailClassService.sendEmail(param);
    }

}


